<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
 <div class="Wrapper">


		<form id="fnc_prj_bsc_info_form" >
             <div class="fieldset1 tabel_col clearFix">
              <div class="fieldBox col_100">
                    <div class="label">项目名称</div>
                <div class="field">
                     <span id="fncprjnm" name="fncprjnm">&nbsp;${fncPrjBscInfo.fncprjnm}</span>
                </div>
                <div style="display: none">
                </div>
             </div>
             <div class="fieldBox col_50">
                <div class="label">金融机构</div>
                <div class="field">
                    <span id="fncinsNM" name="fncinsNM">&nbsp;${fncPrjBscInfo.fncinsNM}</span>
                </div>
                <div style="display: none">
                </div>
             </div>
                             <div class="fieldBox col_50">
                    <div class="label">金融机构类型</div>
                    <div class="field">
                    <span id="instypeNM" name="instypeNM">&nbsp;${fncPrjBscInfo.instypeNM}</span> 
                </div>
                <div style="display: none">
                </div>
             </div>
             <div class="fieldBox col_100">
                    <div class="label">融资报价</div>
                <div class="field">
                  <span id="fncscmNM" name="fncscmNM">&nbsp;${fncPrjBscInfo.fncscmNM}</span>
                </div>
                <div style="display: none">
                </div>
             </div>
           <div class="fieldBox col_50">
                    <div class="label">国家</div>
                <div class="field">
                  <span id="countryNM" name="countryNM">&nbsp;${fncPrjBscInfo.countryNM}</span>
                </div>
                <div style="display: none">
                </div>
             </div>
                
		 <div class="fieldBox col_50">
                <div class="label">业务类型</div>
                <div class="field">
                   <span id="bustypeNM" name="bustypeNM">&nbsp;${fncPrjBscInfo.bustypeNM}</span>
                </div>
                <div style="display: none">
                </div>
              </div>
          <div class="fieldBox col_50">
                    <div class="label">项目金额</div>
                <div class="field">
                    <span id="fncprjamt" name="fncprjamt">&nbsp;${fncPrjBscInfo.fncprjamt/100}</span>
                </div>
                <div style="display: none">
                </div>
             </div>   
                       <div class="fieldBox col_50">
                    <div class="label">融资金额</div>
                <div class="field">
                    <span id="fncfiamt" name="fncfiamt">&nbsp;${fncPrjBscInfo.fncfiamt/100}</span>
                </div>
                <div style="display: none">
                </div>
             </div>  
             
                <div class="fieldBox col_50">
                    <div class="label">实际融资金额</div>
                <div class="field">
                    <input name="acFiAmt" id="acFiAmt" type="text" readonly="readonly" class="ui-textbox" value="${fncPrjBscInfo.acFiAmt/100}" onchange="changeAmt(this.value)"  validate="{number:true,required:true}" >
                </div>
                <div style="display: none">
                </div>
             </div>          
             <!--  <div class="fieldBox col_50">
                    <div class="label">我司金额</div>
	                <div class="field">
	                	<fmt:formatNumber type="number" value="${fncPrjBscInfo.myCompMoney/100}" pattern=".##"/>
	                </div>
             </div>-->
              <div class="fieldBox col_50">
                    <div class="label">首付款金额</div>
                <div class="field">
                    <input name="fstpyamtall" id="fstpyamtall"  type="text"  class="ui-textbox" value="" readonly="readonly" validate="{number:true,required:true}" >
                <span id="zk" name="zk" style="color:red"></span>
                </div>
                <div style="display: none">
                </div>
             </div> 
              <div class="fieldBox col_50">
                    <div class="label">首付款是否坐扣</div>
                <div class="field">
                    <input name="wthrddctNM" id="wthrddctNM" readonly="readonly" type="text"  class="ui-textbox" value="${fncPrjBscInfo.wthrddct}" readonly="readonly">
                </div>
                <div style="display: none">
                </div>
             </div>
                   
                <div class="fieldBox col_50">
                    <div class="label">实际到账金额</div>
                <div class="field">
                    <input name="transam" id="transam"  readonly="readonly" type="text"  class="ui-textbox" value="${fncPrjBscInfo.transam/100.00}" validate="{number:true,required:true}" >
                </div>
                <div style="display: none">
                </div>
             </div> 
             <div class="fieldBox col_50">
                    <div class="label">实际到账日期</div>
                <div class="field">
                   <input name="transtm" id="transtm"  type="text" readonly="readonly"  class="ui-datepicker" value="" validate="{required:true}">
                </div>
                <div style="display: none">
                </div>
             </div>
              	  <input name="prjid" id="prjid" type="hidden" class="ui-textbox" value="${id}">
                  <input name="fncinsid" id="fncinsid" type="hidden" class="ui-textbox" value="${fncPrjBscInfo.fncinsid}">
                  <input name="fstpydepadd" id="fstpydepadd" type="hidden" class="ui-textbox" value="${fncPrjBscInfo.fstpydepadd/100.00}">
                  <input name="fstpyamt" id="fstpyamt" type="hidden" class="ui-textbox" value="${fncPrjBscInfo.fstpyamt/100.00}">    
                  
            </div>
            
            
            	
            <div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">到账明细</span>
						
					</div>
					<div class="fieldBox col_100">
			
						<div style="margin-left: auto;margin-right: 10px;width:300px;">
							<input name="accNotem" id="accNotem"   type="hidden" class="ui-textbox" value="" >	
				            <input name="transacctem" id="transacctem"   type="hidden"  class="ui-textbox" value="" >
				            <input name="transbanktem" id="transbanktem"  type="hidden" class="ui-textbox" value="" >	
						    <input name="transanttem" id="transanttem"  type="hidden" class="ui-textbox" value="">	
						</div>
					</div>
					<div class="fieldBox col_100">
							<div id="cost1" class="sq-grid">
							</div>
					</div>
            </div>
            
               <div id="tablesfk" class="fieldset1 tabel_col tabel_col_s clearFix">
			<div class="caption">
				<span class="title">确认到账信息</span>
			</div>
			<div class="fieldBox col_100" style="display:none;">
			</div>
			<table id="fstpyTable" class="sq-formTable">
				<tbody>
					<tr>
						<td style="padding: 0;text-align: center;">
							<table id="tableMain" class="sq-formTable no-border">
								<thead>
									<tr>
										<th class="tbLabel" style="text-align: center;">费用名称</th>
										<th class="tbLabel" style="text-align: center;">费用比例(%)</th>
										<th class="tbLabel" style="text-align: center;">费用基数</th>
										<th class="tbLabel" style="text-align: center;">费用金额</th>
										<th class="tbLabel" style="text-align: center;">实际费用金额</th>
										<th class="tbLabel" style="text-align: center;">计划退回时间</th>
										<th class="tbLabel" style="text-align: center;">备注</th>
									</tr>
								</thead>
								<tbody>
									<tr id="totalTr">
										<td style="text-align: right;" colspan="3">合计：</td>
										<td style="text-align: center;"><span name="totalCost" ></span></td>
										<td style="text-align: center;" ><input name="totalPay" type="text" readonly="readonly" value="" disabled="disabled"></td>
										<td style="text-align: center;" ></td>
									</tr>
								</tbody>
							</table>
						</td>
					</tr>
				</tbody>
			</table>
		</div>

      </div>
       
	      
	         
         
        </form>
     
             
        </div>

    
	<script type="text/javascript">
	  var pageInApp={
	    		flag:true
	    };
	  var id ='${id}';
	  var selectOrgCd = "";
	   var searchOrgTree = null;
	  var firstNode = null;
	  var textName='${orgTextName}';//节点名称
	  var orgData = null;
		var id ="";//初始值
		var detailFlag = '${detailFlag}';
		var isFlow = '${isFlow}';
		var editFlag;
		var griddata1;
$(function () {
	
	
	//initPayList();
	initData1();
	f_initCostData1();
	
	var transtm = "${fncPrjBscInfo.transtm}";
//	alert(transtm);
	if(null != transtm&&transtm!=''){
		var date = new Date(transtm);
	//	alert(DateUtils.formatDate(date, DateUtils.YYYY_MM_DD));
		$("#transtm").val(DateUtils.formatDate(date, DateUtils.YYYY_MM_DD));
	}
	
	//liger.get("transacc").selectValue("${fncPrjBscInfo.transacc}"); 
	//alert($("#fstpyamtall").val());
});
	//初始化数据
	function initData1(){

	if($("#fstpydepadd").val()==""){
		$("#fstpydepadd").val(0);
	}
	
	
	
	$("#transam").ligerTextBox({ nullText: '请填写', currency: true });
	
			var wthrddctNM=$("#wthrddctNM").val();
			//alert(wthrddctNM);
			 if(wthrddctNM==0){
				 $("#wthrddctNM").val("否");
				 $("#tablesfk").hide();
				 $("#acFiAmt").attr("readonly","readonly");
				
			     $("#transam").val( $("#acFiAmt").val());
			 }else{
				 $("#wthrddctNM").val("是");
				 
				 $("#zk").html("(包含坐扣："+new Number($("#fstpydepadd").val())+")");
				 $("#transam").val( $("#acFiAmt").val()- $("#fstpydepadd").val());
				 $("#tablesfk").show();
				 initData(); 
			 }
			 if(wthrddctNM==2){
				
				 $("#acFiAmt").attr("readonly",false);
				 $("#wthrddctNM").val("是/否");
			 }
			 
			
	          	$("#fncprjamt").html("&nbsp;"+new Number("${fncPrjBscInfo.fncprjamt/100.00}"));

				$("#fncfiamt").html("&nbsp;"+new Number("${fncPrjBscInfo.fncfiamt/100.00}"));	 
				$("#fstpyamta").val(new Number($("#fstpyamt").val()));
				$("#fstpydepadd").val(new Number($("#fstpydepadd").val()));
				//alert(new Number($("#fstpyamt").val())+new Number($("#fstpydepadd").val()));
				$("#fstpyamtall").val(new Number($("#fstpyamt").val())+new Number($("#fstpydepadd").val()));
			//	alert($("#fstpyamtall").val());
	        	$("#acFiAmt").val(new Number($("#acFiAmt").val()));
	        	$("#transam").val(new Number($("#transam").val()));
				 changeAmt(new Number($("#acFiAmt").val()));
	        	
				//alert($("#fstpyamtall").val());
				$("#acFiAmt").ligerTextBox({ nullText: '请填写', currency: true });
				$("#transam").ligerTextBox({ nullText: '请填写', currency: true });	
				$("#fstpyamtall").ligerTextBox({ nullText: '请填写', currency: true });
				$("#fnc_prj_bsc_info_form").ligerForm({
				    validate: true
				});
				 var ligerForm = liger.get("fnc_prj_bsc_info_form");
			 $("#fnc_prj_bsc_info_form").check_ligerFormEditor();
	

			
	}
	var pageInTab = null;
	  var loadedTabs=[]

	
	  

	  
   
	
	//初始化Tab
   	//修改初始化数据
		function initData() {
			var dataId = $("#prjid").val();
			if (StringUtils.isEmpty(dataId))
				return;
			var _url = '<%=path%>/rfbase/fncprjfstpyinfo/getById.do';
			var wthrDdctFstPay = 1; // 坐扣的数据
			AjaxUtils.ajaxGet(_url, {
				fncPrjId : dataId,
				wthrDdctFstPay : wthrDdctFstPay,
				from : "confirmAccount"
			}, initCallback);
		}

		//初始化回调
		function initCallback(msg) {
			if (msg.success == 1) {
				setData(msg.data);//设置数据
			} else {
				UIUtils.alertError(msg.info);
			}
		}
		
		//修改时候设置页面数据
		function setData(data) {
			var form = new liger.get("fnc_prj_bsc_info_form");
			
			
			
			//首付款信息
			var fstpyVos = data.fncPrjFstpyInfoVOs;
			
			console.log(fstpyVos);
			for (var i = 0; i < fstpyVos.length; i++) {
				addRow();
				var tr = $('#tableMain tbody tr:eq('+i+')');
				if(fstpyVos[i].costPct== '' || null ==fstpyVos[i].costPct){
					fstpyVos[i].costPct = '--';
					fstpyVos[i].costCrdnltNm = '--';
					if(fstpyVos[i].costPct== '' || null == fstpyVos[i].costAmt){
						fstpyVos[i].costAmt = fstpyVos[i].fscpCostAmt;
					}
				}else{
				//	fstpyVos[i].costPct = fstpyVos[i].costPct*100+"%";
					fstpyVos[i].costCrdnltNm = "融资金额";
				}
				tr.find("span[name='costNm']").html(fstpyVos[i].costNm);
				tr.find("span[name='costPct']").html(fstpyVos[i].costPct*100);
				tr.find("span[name='costCrdnltNm']").html(fstpyVos[i].costCrdnltNm);
				tr.find("span[name='costAmt']").html(fmoney(fstpyVos[i].costAmt, 2));
				tr.find("input[name='payAmt']").val(fstpyVos[i].payAmt);
				
				tr.find("input[name='id']").val(fstpyVos[i].id);
				tr.find("input[name='scmChrgId']").val(fstpyVos[i].scmChrgId);
				tr.find("input[name='rmrk']").val(fstpyVos[i].rmrk);
				tr.find("span[name='reReturnTm']").html(renderDate("","",fstpyVos[i].reReturnTm));
				
				//tr.find("input[name='payAmt']").ligerTextBox({ nullText: '请填写', currency: true });
			}
			
			//setTotal();
			var acfiamt=$('#acFiAmt').val();
			if(acfiamt==""){acfiamt=0;}
			 changeAmt(acfiamt);
			/* isWthrDdct(data.wthrDdct); */
		};
		function addRow(fstpyVo){
			$('#totalTr').before('<tr>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costNm" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costPct" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costCrdnltNm" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costAmt" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<input name="payAmt" type="text" readonly="readonly" value="" onchange="setTotal()">'+
						'<input name="id" type="hidden" value="" >'+
						'<input name="scmChrgId" type="hidden" value="" >'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<span name="reReturnTm" ></span>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<input name="rmrk" type="text" readonly="readonly" value="" >'+
				'</td>'+
			'</tr>');
		}
		
		function changeAmt(val){
			if(isNaN(val)){
				val=new Number("${fncPrjBscInfo.acFiAmt/100.00}");
			}
			//alert(val);
			var fstpyTr = $('#tableMain tbody tr');
			for (var i = 0; i < fstpyTr.length - 1; i++) {
				var amt = 0;
				var costPct = $.trim($(fstpyTr[i]).find("span[name='costPct']").text());
				costPct = costPct.replace("%","");
				var costAmt = $.trim($(fstpyTr[i]).find("span[name='costAmt']").text());
				console.log("-----------"+costPct+"=="+costPct);
				if(costPct != '--' && costPct != ''){
					amt = val*costPct/100;
				}else{
					amt = costAmt;
				}
				$(fstpyTr[i]).find("span[name='costAmt']").html(fmoney(amt, 2));
				//$(fstpyTr[i]).find("input[name='payAmt']").val(amt);
				
				$(fstpyTr[i]).find("input[name='payAmt']").ligerTextBox({ nullText: '请填写', currency: true });
			}
		
			setTotal();
		}
		
		function setTotal(){
		//	alert(1);
          var val1=$("#acFiAmt").val().replace(/,/g,"");
         // alert("实际融资金额="+val1)
          if(isNaN(val1) || val1==0){
				val1=new Number("${fncPrjBscInfo.acFiAmt/100.00}");
			}
   
			var totalPayAmt =0;
			var totalCostAmt = 0;
			var fstpyTr = $('#tableMain tbody tr');
			for (var i = 0; i < fstpyTr.length - 1; i++) {
				var costAmt = $(fstpyTr[i]).find("span[name='costAmt']").text().replace(/,/g,"");
				var payAmt = $(fstpyTr[i]).find("input[name='payAmt']").val().replace(/,/g,"");
				if($.trim(costAmt)==''||null == costAmt){
					costAmt = 0;
				}
				if($.trim(payAmt)==''||null == payAmt){
					payAmt = 0;
				}
				totalCostAmt += parseFloat(costAmt);
				totalPayAmt += parseFloat(payAmt);
			}
			//  alert("totalCostAmt="+totalCostAmt);
			//  alert("totalPayAmt="+totalPayAmt);
			$('#totalTr').find("span[name='totalCost']").html(totalCostAmt);
			$('#totalTr').find("input[name='totalPay']").val(totalPayAmt);
			var fncval=$('#acFiAmt').val();
		//	if(fncval==""){fncval=0;}
			if("${fncPrjBscInfo.wthrddct}"!="0"){
			//	alert(totalPayAmt);
				$('#fstpydepadd').val(totalPayAmt);
				//alert(new Number(val1));
			//  alert("fstpydepadd="+$('#fstpydepadd').val());
			//	alert(new Number(fncval)-new Number(totalPayAmt));
				 $("#transam").val( val1- $("#fstpydepadd").val().replace(/,/g,""));
			//	 alert("transam="+$('#transam').val());
				 
			//	alert($("#transam").val());
			}
			if("${fncPrjBscInfo.wthrddct}"=="0"){
				
				$('#transam').val($("#acFiAmt").val());
				
			}
			//alert($("#fstpydepadd").val());
			$("#fstpyamtall").val(new Number($("#fstpyamt").val())+new Number($("#fstpydepadd").val()));
			//alert($("#fstpyamtall").val());
			 $("#zk").html("(包含坐扣："+new Number($("#fstpydepadd").val())+")");
		}
	//保存项目基础信息
	function save(){
		//alert($("#acFiAmt").val());
		//alert($("#fstpyamtall").val());
        var ligerForm = liger.get("fnc_prj_bsc_info_form");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var transam=new Number($("#transam").val().replace(/,/g,""));
    	if(transam<=0){
            top.$.ligerDialog.SQalert({content:"实际到账金额必须大于0！",SQ_type: "warning"});
            return false; 	
    	}
        var transanttem=new Number($("#transanttem").val().replace(/,/g,""));
    	if(transam-transanttem!=0){
            top.$.ligerDialog.SQalert({content:"到账明细总和必须等于实际到账金额",SQ_type: "warning"});
            return false; 	
    	}
    	
    	var ckrzd=validateGrid();
        if(!ckrzd){
           return false; 	
        }
    	
    	
    	
	    				  var data = ligerForm.getData();
	    			       data["id"]=$("#prjid").val();
	    			       data["transacc"]=$("#transacc").val();
	    			       var transmess = griddata1.getData();
	    			       data["transmess"] = JSON.stringify(transmess);
	    			       data["fstpydepadd"]=$("#fstpydepadd").val();
	    			       if(data["orgCd"]==""){
	    			       data["orgCd"]='${orgCd}';
	    			       }
	    			       var checksfk=0;
	    			       //首付款信息
	    					var fstpyArray = [];
	    					var fstpyTr = $('#tableMain tbody tr');
	    					for (var i = 0; i < fstpyTr.length - 1; i++) {
	    						var id = $.trim($(fstpyTr[i]).find("input[name='id']").val());
	    					
	    						var scmChrgId = $.trim($(fstpyTr[i]).find("input[name='scmChrgId']").val());
	    						var costNm = $.trim($(fstpyTr[i]).find("span[name='costNm']").text());
	    						var costAmt = $.trim($(fstpyTr[i]).find("span[name='costAmt']").text().replace(/,/g,""));
	    						var payAmt = $.trim($(fstpyTr[i]).find("input[name='payAmt']").val().replace(/,/g,""));
	    						if(payAmt=="" || payAmt<=0){
	    							 top.$.ligerDialog.SQalert({content:"首付款明细必须大于0！",SQ_type: "warning"});
	    							 checksfk=1;
	    							 break;
	    						}
	    						var rmrk = $.trim($(fstpyTr[i]).find("input[name='rmrk']").val());
	    						if( new Number(payAmt)-new Number(costAmt)!=0 && (rmrk == ""|| rmrk == null)){
	    							$(fstpyTr[i]).find("input[name='rmrk']").addClass('errorRequried');
	    							UIUtils.alertWarning("有备注信息未填写!");
	    							
	    							return false;
	    						}else{
	    							$(fstpyTr[i]).find("input[name='rmrk']").removeClass('errorRequried');
	    						}
	    						var fstpy = {
	    							"id" : id,
	    							"scmChrgId" : scmChrgId,
	    							"fncPrjId" : data.fncPrjId,
	    							"prePayDate" : data.expWdDate,
	    							"costNm" : costNm,
	    							"costAmt" : costAmt,
	    							"payAmt" : payAmt,
	    							"rmrk" : rmrk
	    						}
	    					
	    						fstpyArray.push(fstpy);
	    					}
	    					if(checksfk==1){
	    						return false;
	    					}
	    					data["fstpyArray"] = JSON.stringify(fstpyArray);
	    					data["totalPay"]= $("input[name='totalPay']").val();
	    			        data["transflag"]="1";

	    			       
	    			       
	    			       
	    			        var url = '<%=path%>/rfbuss/fncprjbscinfo/add.do';

	    			        var wait_dialog;
	    			        $.ajax({
	    			    		type: 'post',
	    			    		dataType:'json',
	    			    		data:data,
	    			    		url: url,
	    			    		beforeSend: function(){
	    					          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	    					     },
	    			    		success:function(msg){
	    			    			 wait_dialog.close();
	    			    			  var callback=GET_W2Wcallback();
	    			    	           

	    			    			 if(msg.success == 1){
	    			    				// if(callback) callback("success",msg.info);
	    			    				//	 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	    						          	 	$("#prjid").val(msg.data);
	    						          	 //	pageInApp.flag=false;
	    						          	  Remove_navTab();
                                             //  cancelBtn();
	    			    			 }else{
	    			    				// if(callback) callback("error");
	    			    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			    			 }
	    			    		}
	    			    	});
     	    	
	}
	//取消
	function cancelBtn(){
		  var TAB=top.mainApp.parentTab;
          var currentTabid=TAB.getSelectedTabItemID();
          if(top.tab.isTabItemExist("${currentTabid}")){
	        	  top.tab.reload("${currentTabid}");  
	          }
		 top.tab.removeTabItem(currentTabid);
	}

	     function initPayList(){
	   	   var instid = "${fncPrjBscInfo.fncinsid}";
	   	
	   	     var transbox= $("#transacc").ligerComboBox({
	   	      columns: [
		            /* { header: '账户类型', name: 'accTypNm', width: 100},  */
	                { header: '开户行名', name: 'bkNm', width: 100}, 
	                { header: '账户名称', name: 'accNm', width: 120},
	                { header: '账号', name: 'accNo', width: 120},
		             
	               ],
	            url:'<%=path%>/rfbase/fncprjfstpyinfo/initPayList.do?insId='+instid,
	           onChangeValue: function (value){
	 	        	
	 	        
	 	        	  var obj=transbox.getValue();
	 	        	
	 	        	  //  $("#expwdbank").val(obj.bkNm);
	 	        	  var url1="<%=path%>/rfbuss/fncprjbscinfo/initPaybank.do?id="+obj;
	 	        	 $.ajax({
  			    		type: 'get',
  			    		dataType:'json',
  			    		url: url1,
  			    		success:function(msg){
  			    		
  			    					 $("#transbank").val(msg.data);
  						          	 	//pageInApp.flag=false;
  			    			
  			    		}
  			    	});  
	 	             },
	            ajaxType :'GET',
	            width: 200, 
	            isMultiSelect: false,
	            isShowCheckBox:false, 
	            slide: false,
	            selectBoxWidth: 680, 
	            selectBoxHeight: 740,
	            valueField: 'id', 
	            textField: 'accNo',
	 	         
	 	       });
	   	   
	   	

	   	
	     }
	 	function fmoney(s, n)   
		{   
		   n = n > 0 && n <= 20 ? n : 2;   
		   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
		   var l = s.split(".")[0].split("").reverse(),   
		   r = s.split(".")[1];   
		   t = "";   
		   for(i = 0; i < l.length; i ++ )   
		   {   
		      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
		   }   
		   return t.split("").reverse().join("") + "." + r;   
		} 
	 	
		//选择页面
		function choosePage(){
		
	        $.ligerDialog.open({  title: '选择账户',height: 500,width: 850, url: '<%=path%>/rfbuss/fncprjbscinfo/toChooseCompAccPage.do?flag=tran'});
		}
		
		
		 function f_initCostData1()
		    { 
				if(editFlag==''){
					editFlag=true;
				}
				var id=$("#prjid").val();
				var url='<%=path%>/rfbuss/fncprjdrawmon/initList.do?id='+id;
		    	griddata1 = $("#cost1").ligerGrid({
		    		url:url,
		            method: 'get',
		                columns: [
 
			                { display: '到账日期', name: 'dmTm', width: 250,format: 'yyyy-MM-dd', editor: { type: 'date'},render:renderDate }, 
			            
			                { display: '到账金额', name: 'dmAm',
			                    editor: { type: 'text' }, align: 'left', width: 280,totalSummary:
			                    {
			                        render: function (suminf, column, cell)
			                        {
			                        	//alert(suminf.count+":"+suminf.sum);
			                        	$("#transanttem").val(suminf.sum); 
			                        	
			                            return '<div>总计:' + suminf.sum.toFixed(2) + '</div>';
			                        },
			                        align: 'right'
			                    }
			                },
			               
			                { display: '收款账号', name: 'dmAcc', 
			                    editor: { type: 'text',readonly:true }, align: 'left', width: 200
			                },
			                { display: '我司账户', name: 'dmAccNm', 
			                    editor: { type: 'text',readonly:true }, align: 'left', width: 200
			                },
			                { display: '收款银行', name: 'dueBank',
			                    editor: { type: 'text',readonly:true  }, align: 'left', width: 580
			                },
			                { display: '账号编号', name: 'accId',hide: true, 
			                    editor: { type: 'text' }, align: 'left', width: 180
			                }			               
			                
			               // getOptColumn()
		                ],
		                onSelectRow: function (rowdata, rowindex)
		                {
		                   // $("#txtrowindex").val(rowindex);
		                },
		                usePager: false,
		                root: 'rows',
		                record: 'total',
		                hideLoadButton: true,
		                width: '100%',
		                height: 300,
		                heightDiff: -2,
		                enabledEdit: false,
		                isScroll: false,
		                checkbox: editFlag,
		                rownumbers: true,
		                allowUnSelectRow: true,
		                alternatingRow: false,
		                enabledSort: false
		               
		            }); 
		    	
		    	
		    }
		 
		//获取操作列
			function getOptColumn(){
				
				var column = {
		                display: '操作',
		                isSort: false,
		                width: 200,
		                align:'left',
		                render: function (rowdata, rowindex, value){
		                	 var h="";
		                	  h='<a class="sq-button-hasicon" href="javascript:chbankBtn(';
		                      h+="'"+rowindex+"'";
		                      h+=')"><i class="sqBtnIco_4"></i>选择银行</a>'
		                    
		                    return h;
		                }
		            }
				return column;
			}
			 $("#scm_cost2_add_btn_id").click(function (event) {
				   griddata1.addRow({});
			    });
			    
				$("#scm_cost2_del_btn_id").click(function (event) {
			        var selectedRows = griddata1.getSelectedRows();
			        if(selectedRows.length ==0){
						$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
						return;
					}			
			        griddata1.deleteSelectedRow(); 
			    });
				
				//格式化时间
				function renderDate(rowdata, index, value){
					var dateStr = "";
					if(null != value){
						var date = new Date(value);
						dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
					}
					return dateStr;
				}
				var rownum1;
				  function chbankBtn(row)
			        {
					  rownum1=row;
					  choosePage();
			           // var selected = manager.getSelected();
			          //  if (!selected) { alert('请选择行'); return; }
			            
			        }
				  function chbankBtn1()
			        {
					 // alert($("#transbanktem").val());
					  griddata1.updateRow(rownum1,{
			                dueBank:$("#transbanktem").val(),
			                accId : $("#transacctem").val(),
			                dmAcc : $("#accNotem").val()
			            });
			            
			        }
				  
					function validateGrid() {  
			            var rows = griddata1.rows;  
			            for (var i = 0; i < rows.length; i++) { 
			            	//alert(rows[i].costNm);
			                if (rows[i].dmTm==null || rows[i].dmTm=="") {  
			                    $.ligerDialog.warn("到账明细第"+(i+1)+"行[到账日期]不能为空");  
			                    return false;  
			                }  
			                if (rows[i].dmAm==null ||rows[i].dmAm=="") {  
			                    $.ligerDialog.warn("到账明细第"+(i+1)+"行[到账金额]不能为空");  
			                    return false;  
			                } 
			                if (rows[i].accId==null ||rows[i].accId=="") {  
			                    $.ligerDialog.warn("到账明细第"+(i+1)+"行[银行账号]需要选择");  
			                    return false;  
			                } 
			                if (rows[i].dmAm<0) {  
			                    $.ligerDialog.warn("到账明细第"+(i+1)+"行[到账金额]不能为负数");  
			                    return false;  
			                }  
			            }  
			           
			            return true;  
			        }  			 
    </script>
<style type="text/css">
		.errorRequried{
			border:1px solid red;
			/* height:20px; */
		}
	</style>
	 <button id="hiddenBtn" style="background-color:#666666; display:none;" onclick="chbankBtn1()">Hidden Button</button>
</body>
</html>